/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DynamicDomainPanel.java
 *
 * Created on 2009-1-17, 23:37:21
 */

package com.guzzservices.easydomain.ui.panel;

import com.guzzservices.easydomain.logic.DomainManager;
import com.guzzservices.easydomain.logic.domain.DynamicDomainChangeListener;
import java.awt.Color;
import javax.swing.JTable;

/**
 *
 * @author Administrator
 */
public class DynamicDomainPanel extends javax.swing.JPanel implements DynamicDomainChangeListener{

    /** Creates new form DynamicDomainPanel */
    public DynamicDomainPanel() {
        initComponents();
        DomainManager.getDomainManager().addDynamicDomainChangeListener(this) ;
        refreshRunStatus() ;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        runStatusSwingLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        dynamicDomainsTable = new javax.swing.JTable();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.guzzservices.easydomain.ui.frame.DDSProjectApp.class).getContext().getResourceMap(DynamicDomainPanel.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N

        jPanel1.setBackground(resourceMap.getColor("jPanel1.background")); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setPreferredSize(new java.awt.Dimension(581, 25));

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setAlignmentX(0.5F);
        jLabel1.setName("jLabel1"); // NOI18N

        runStatusSwingLabel.setText(resourceMap.getString("runStatusSwingLabel.text")); // NOI18N
        runStatusSwingLabel.setName("runStatusSwingLabel"); // NOI18N

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(runStatusSwingLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
                .add(runStatusSwingLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        dynamicDomainsTable.setModel(new com.guzzservices.easydomain.ui.render.DynamicDomainTableDataModel());
        dynamicDomainsTable.setIntercellSpacing(new java.awt.Dimension(8, 4));
        dynamicDomainsTable.setName("dynamicDomainsTable"); // NOI18N
        dynamicDomainsTable.setRowHeight(25);
        dynamicDomainsTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(dynamicDomainsTable);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 581, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 367, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable dynamicDomainsTable;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel runStatusSwingLabel;
    // End of variables declaration//GEN-END:variables

    public void notifyDomainChanged() {
        refreshTable() ;
        refreshRunStatus() ;
    }

    protected void refreshRunStatus(){
        DomainManager dm = DomainManager.getDomainManager() ;
        int active = dm.getActiveDynamicDomainCount() ;

        runStatusSwingLabel.setForeground(Color.ORANGE);
        runStatusSwingLabel.setText("现已激活动态域名：" + active + "个");
    }

    public void refreshTable(){
        this.jScrollPane1.repaint() ;
    }

    public JTable getDynamicDomainsTable() {
        return dynamicDomainsTable;
    }

}
